package com.campus.counseling.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.campus.counseling.entity.TestDimension;
import com.campus.counseling.model.common.Result;
import com.campus.counseling.model.dto.TestDimensionDTO;
import com.campus.counseling.model.query.TestDimensionQuery;
import com.campus.counseling.model.vo.TestDimensionVO;
import com.campus.counseling.service.TestDimensionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Api(tags = "测试维度管理")
@RestController
@RequestMapping("/api/test-dimensions")
@RequiredArgsConstructor
public class TestDimensionController {

    private final TestDimensionService testDimensionService;

    @ApiOperation("获取维度列表")
    @GetMapping("/list")
    public Result<Page<TestDimensionVO>> list(TestDimensionQuery query) {
        return Result.success(testDimensionService.list(query));
    }

    @ApiOperation("获取维度详情")
    @GetMapping("/{id}")
    public Result<TestDimensionVO> getDimension(@PathVariable Long id) {
        return Result.success(testDimensionService.getDimension(id));
    }

    @ApiOperation("创建维度")
    @PostMapping
    @PreAuthorize("hasAnyRole('admin', 'superadmin')")
    public Result<Void> createDimension(@RequestBody @Valid TestDimensionDTO dto) {
        testDimensionService.createDimension(dto);
        return Result.success();
    }

    @ApiOperation("更新维度")
    @PutMapping("/{id}")
    @PreAuthorize("hasAnyRole('admin', 'superadmin')")
    public Result<Void> updateDimension(@PathVariable Long id, @RequestBody @Valid TestDimensionDTO dto) {
        testDimensionService.updateDimension(id, dto);
        return Result.success();
    }

    @ApiOperation("删除维度")
    @DeleteMapping("/{id}")
    @PreAuthorize("hasAnyRole('admin', 'superadmin')")
    public Result<Void> deleteDimension(@PathVariable Long id) {
        testDimensionService.deleteDimension(id);
        return Result.success();
    }
} 